package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author ：mmzs
 * @date ：Created in 2020/7/29 17:25
 * @description：数据库连接
 * @modified By：
 * @version: $
 */
public class JDBCUtil {

    final public static String userName = "root";
    final public static String passWord = "123456";
//    final public static String userName = "niu";
//    final public static String passWord = "12300zaq";
    final public static String className = "com.mysql.jdbc.Driver";
//    final public static String JDBCUrl = "jdbc:mysql://localhost:3306/paper_citation_ai?useSSL=true&serverTimezone=GMT%2B8";
    final public static String JDBCUrl = "jdbc:mysql://localhost:3306/paper_citation_thelancet?useSSL=true&serverTimezone=GMT%2B8";
//    final public static String JDBCUrl = "jdbc:mysql://1.15.136.97:3306/lunwen?useUnicode=true&characterEncoding=UTF-8";
//    final public static String JDBCUrl = "jdbc:mysql://1.15.136.97:3306/lunwen?useSSL=true&serverTimezone=GMT%2B8";


    public JDBCUtil() {
        try {
//            System.out.println(Driver.class.getClassLoader());
//            Class.forName(this.className);
            Class.forName(className).getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
        try {
            return DriverManager.getConnection(JDBCUrl, userName, passWord);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        Connection connection = JDBCUtil.getConnection();
    }

}
